using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace OA.UI
{
    public class HtmlFilter:System.IO.Stream
    {
        Stream Response = null;

        public HtmlFilter(Stream response)
        {
            Response = response;
        }

        public override bool CanRead
        {
            get { return Response.CanRead; }
        }

        public override bool CanSeek
        {
            get { return Response.CanSeek; }
        }

        public override bool CanWrite
        {
            get { return Response.CanWrite; }
        }

        public override void Flush()
        {
            Response.Flush();
        }

        public override long Length
        {
            get { return Response.Length; }
        }

        public override long Position
        {
            get
            {
                 return Response.Position; 
            }
            set
            {
                Response.Position = value;
            }
        }

        public override int Read(byte[] buffer, int offset, int count)
        {
            return Response.Read(buffer, offset, count);
        }

        public override long Seek(long offset, SeekOrigin origin)
        {
            return Response.Seek(offset, origin);
        }

        public override void SetLength(long value)
        {
            Response.SetLength(value);
        }

        public override void Write(byte[] buffer, int offset, int count)
        {
            /* //简体转繁体
            var resp=System.Web.HttpContext.Current.Response;
            if (resp.ContentType.EndsWith("text/html")) //|| resp.ContentType.EndsWith("application/x-javascript")
            {
                var encoding = resp.ContentEncoding;
                var str = encoding.GetString(buffer, offset, count);
                str = Microsoft.VisualBasic.Strings.StrConv(str, Microsoft.VisualBasic.VbStrConv.TraditionalChinese);
                buffer = encoding.GetBytes(str);
                offset = 0;
                count = buffer.Length;
            }*/
            Response.Write(buffer, offset, count);
        }
    }
}
